<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\DB;

/**
 * 数据迁移 后台管理员表
 * Class CreateAdminUserTable
 */
class CreateAdminUserTable extends Migration
{
    /**
     * 构建数据表
     * Run the migrations.
     */
    public function up(){
        Schema::create('admin_user', function(Blueprint $table){
            $table->engine = 'InnoDB';
            $table->charset = 'utf8mb4';
            $table->collation = 'utf8mb4_general_ci';

            $table->increments('id')->comment('主键');
            $table->string('name', 255)->nullable(false)->comment('登录名称');
            $table->string('password', 255)->nullable(false)->comment('登录密码');
            $table->tinyInteger('sex')->unsigned()->default(0)->nullable(true)->comment('性别，0保密，1男，2女，默认0');
            $table->tinyInteger('status')->unsigned()->default(0)->nullable(true)->comment('状态，0禁用，1启用，默认为0');
            $table->string('nickname', 255)->nullable(true)->comment('呢称');
            $table->string('phone', 20)->nullable(true)->comment('联系电话');
            $table->string('real_name', 255)->nullable(true)->comment('真实姓名');
            $table->string('en_name', 255)->nullable(true)->comment('英文名');
            $table->string('position', 255)->nullable(true)->comment('职称');
            $table->string('last_login_ip', 32)->nullable(true)->comment('最后登录的IP');
            $table->dateTime('last_login_time')->nullable(true)->comment('最后登录日期');
            $table->dateTime('updated_at')->nullable(true)->comment('修改日期');
            $table->dateTime('created_at')->nullable(true)->comment('建立日期');

            $table->unique('name','name');
        });
        DB::statement("ALTER TABLE `admin_user` comment '后台管理员表'");
    }

    /**
     * 回滚
     * Reverse the migrations.
     */
    public function down(){
        Schema::dropIfExists('admin_user');
    }
}